package com.xiyi.shouxin.dao.admin;

import java.util.ArrayList;
import java.util.List;

import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import com.xiyi.shouxin.dao.BaseRepository;
import com.xiyi.shouxin.dao.JdbcPreparedStatement;
import com.xiyi.shouxin.entity.admin.Role;
import com.xiyi.shouxin.entity.admin.mapper.RoleMapper;

@Repository
public class RoleRepository extends BaseRepository<Role> {
    public RoleRepository() {
        super();
        super.stat = new JdbcPreparedStatement<>(Role.class);
    }

    public List<Role> findByMultiConditionsByPage(String roleName, Sort sort, int page, int size)
            throws Exception {
        List<Object> args = new ArrayList<>();
        List<String> conditions = new ArrayList<>();
        if (StringUtils.hasText(roleName)) {
            conditions.add(stat.GetColumnName("roleName") + " like ? ");
            args.add("%" + roleName + "%");
        }
        return findByMultiConditionsByPage(conditions, args, sort, page, size, new RoleMapper());
    }

    public int countByMultiConditions(String roleName) {
        List<Object> args = new ArrayList<>();
        List<String> conditions = new ArrayList<>();
        if (StringUtils.hasText(roleName)) {
            conditions.add(stat.GetColumnName("roleName") + " like ? ");
            args.add("%" + roleName + "%");
        }

        return countByMultiConditions(conditions, args);
    }

}
